﻿using System.Data.Common;
using System.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using JUtil;
using System.Collections.Specialized;

    public class DatabaseDataObjectOperatorBase : IDatabase, IDataObjectOperator
    {
        private DbProvider DbProvider = DbProvider.OleDb;
        private string connectionString = "Provider=Microsoft.JET.OLEDB.4.0; data source=" + @"E:\GoogleProjectHosting\jelly-asp-net-sample\src\sample\App_Data\NorthWind.mdb";
        private IDatabase db;

        public DatabaseDataObjectOperatorBase()
        {
            // USING ...
            db = DbUtil.GetDbObject(new DbConnectionConfig
            {
                DbProvider = DbProvider,
                ConnectionString = connectionString
            });

            // DSTOR -> CLEAR
            //db = new Database(DbProvider, connectionString);
        }

        #region IDatabase 成員

        public void ExecuteSQL(string sql)
        {
            db.ExecuteSQL(sql);
        }

        public void ExecuteSQL(ICollection<string> SQLs)
        {
            db.ExecuteSQL(SQLs);
        }

        public DataSet SelectSQL(List<KeyValuePair<string, string>> querySQLs)
        {
            return db.SelectSQL(querySQLs);
        }

        public DataTable SelectSQL(string querySQL)
        {
            return db.SelectSQL(querySQL);
        }

        public bool TestConnection()
        {
            return db.TestConnection();
        }

        public DataTable GetSchema(string collectionName)
        {
            return db.GetSchema(collectionName);
        }

        public DbConnectionConfig DbConnectionConfig
        {
            get { return db.DbConnectionConfig; }
        }

        public void ExecuteSP(string procedureName, System.Collections.Hashtable inParameters, System.Collections.Hashtable outParameters, System.Collections.Hashtable retParameters)
        {
            db.ExecuteSP(procedureName, inParameters, outParameters, retParameters);
        }

        public void ExecuteSQL(string sql, System.Collections.Hashtable inParameters)
        {
            db.ExecuteSQL(sql, inParameters);
        }

        public DataTable GetTableSchema(string sql)
        {
            return db.GetTableSchema(sql);
        }

        public int SelectCountSQL(string sql)
        {
            return db.SelectCountSQL(sql);
        }
        #endregion

        #region IDataObjectOperator 成員

        public OrderedDictionary SelectParameters{get; set;}

        #endregion


    }